{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>添加</h5>
                </div>
                <div class="ibox-content layui-form">
                    <div class="layui-row layui-col-space10 layui-form-item ">
                        <input type="hidden" name="id" value="{$id}">
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">标题：</label>
                            <div class="layui-input-block">
                                <input type="text" name="new_title" value="{$res.new_title}" lay-verify="required" placeholder="标题" class="layui-input" maxlength="15">
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">副标题：</label>
                            <div class="layui-input-block">
                                <input type="text" name="new_second_title" value="{$res.new_second_title}" lay-verify="required" placeholder="副标题" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">图片</br>（比例2:1）</label>
                            <input type="hidden" name="new_img" id="lay-img" lay-verify="image">
                            <div class="layui-input-block">
                                <div id="lay-upload">上传图片</div>
                                <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                                    预览图：
                                    <div class="layui-upload-list" id="lay-list">
                                        <img class="layui-append-img" src="{$res.new_img}" onerror="this.src='/static/admin/images/no_img.jpg'">
                                    </div>
                                </blockquote>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8 form-group">
                            <label class="layui-form-label">类型：</label>
                            <div class="layui-input-block">
                                <select name="new_type" lay-filter="role">
                                    <option value="1" {if $res['new_type']==1} selected {/if}>上传图文</option>
                                    <option value="2"  {if $res['new_type']==2} selected {/if}>上传链接</option>
                                </select>
                            </div>
                        </div>
                        {if $res['new_type']==1}
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md10 content">
                            <label class="layui-form-label">内容：</label>
                            <div class="layui-input-block" id="LAY_editor" lay-verify="editor">
                                <p>{$res['new_content']}</p>
                            </div>
                        </div>
                        {else /}
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md10 content" style="display:none">
                            <label class="layui-form-label">内容：</label>
                            <div class="layui-input-block" id="LAY_editor" lay-verify="editor">
                                <p>{$res['new_content']}</p>
                            </div>
                        </div>
                        {/if}
                        {if $res['new_type']==2}
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8 new_link" >
                            <label class="layui-form-label">链接：</label>
                            <div class="layui-input-block">
                                <input type="text" name="new_link" value="{$res['new_link']}" placeholder="链接" class="layui-input" maxlength="200">
                            </div>
                        </div>
                        {else /}
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8 new_link" style="display:none">
                            <label class="layui-form-label">链接：</label>
                            <div class="layui-input-block">
                                <input type="text" name="new_link" value="{$res['new_link']}" placeholder="标题" class="layui-input" maxlength="200">
                            </div>
                        </div>
                        {/if}
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit="" lay-filter="component-form-element">保存
                                </button>
                                <button class="layui-btn layui-btn-primary" onclick="history.go(-1)">关闭</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    var editor = wk.wang({elem:'#LAY_editor'});
    wk.uploadImg({size:5,type:'png,jpg,jpeg',url:"{:url('Upload/upload')}",domain:""});
    layui.use(['form','upload','layedit'], function() {
        var form = layui.form;
//        form.verify({
//            editor:function(value,item){
//                if(editor.txt.html() == '<p><br></p>'){
//                    return '请填写内容';
//                }
//            }
//        });
        form.on('submit(component-form-element)', function (data) {
            data.field.new_content = editor.txt.html();
            $('.layui-btn').addClass('layui-disabled').attr('disabled','disabled');
            $.ajax({
                url:"{:url('update')}",
                type:'post',
                dataType:'json',
                data:data.field,
                success:function(res){
                    if (res.code == 200) {
                        wk.success(res.msg,"{:url('news/index')}")
                    } else {
                        wk.error(res.msg,'','$(".layui-btn").removeClass(\'layui-disabled\').removeAttr(\'disabled\');');
                    }
                }
            })
        });
        form.on('select(role)', function(data){
            if(data.value == 1){
                $(".content").show();
                $(".new_link").hide();
            }else{
                $(".content").hide();
                $(".new_link").show();
            }
        });
//        form.on('select(role1)', function(data){
//            banner_type = data.value;
//            if(data.value == 1){
//                $("#assn_id").show();
//                $("#information_id").hide();
//                $("#post_id").hide();
//                $("#video_id").hide();
//                $("#answer_id").hide();
//            }else if(data.value == 2){
//                $("#assn_id").hide();
//                $("#information_id").show();
//                $("#post_id").hide();
//                $("#video_id").hide();
//                $("#answer_id").hide();
//            }else if(data.value == 3){
//                $("#assn_id").hide();
//                $("#information_id").hide();
//                $("#post_id").show();
//                $("#video_id").hide();
//                $("#answer_id").hide();
//            }else if(data.value == 4){
//                $("#assn_id").hide();
//                $("#information_id").hide();
//                $("#post_id").hide();
//                $("#video_id").show();
//                $("#answer_id").hide();
//            }else {
//                $("#assn_id").hide();
//                $("#information_id").hide();
//                $("#post_id").hide();
//                $("#video_id").hide();
//                $("#answer_id").show();
//            }
//
//        });
    });
</script>

</body>
</html>
